package public

import (
	"MembershipRegist/db"
	"MembershipRegist/models"
)

func (c *Controller) AdminLogin() {
	username := c.GetString("username")
	password := c.GetString("password")
	if username == "" || password == "" {
		c.ResponseFailed(201, "用户名或密码不能为空")
		return
	}
	var admin models.Admin
	if value := db.DB.Where("username = ? and password = ?", username, password).First(&admin); value.Error != nil {
		c.ResponseFailed(202, "用户名或密码错误")
		return
	}

	c.SetSession("admin_id", admin.ID)
	c.ResponseSuccess()
	return
}
